﻿using Little.Soldier.SWIFT;
using Little.Soldier.SWIFT.Definition;
using System.Collections.Generic;
using System.ComponentModel;

namespace Little.Soldier.SWIFT.Messages.Category0
{
  public class MT051 : SwiftMessage
  {
    private static SwiftMessageDefinition MessageDefinition;
    private static SwiftTagDefinition U0002;
    private static SwiftTagSubItemDefinition U0003;
    private static SwiftTagDefinition U0004;
    private static SwiftTagSubItemDefinition U0005;
    private static SwiftTagSequenceDefinition U0006;
    private static SwiftTagDefinition U0007;
    private static SwiftTagSubItemDefinition U0008;
    private static SwiftTagDefinition U000E;
    private static SwiftTagSubItemDefinition U000F;
    private static SwiftTagSubItemDefinition U0010;
    private static SwiftTagSubItemDefinition U0011;
    private static SwiftTagSubItemDefinition U0012;
    private static SwiftTagSubItemDefinition U0013;
    private static SwiftTagSubItemDefinition U0014;
    private static SwiftTagSubItemDefinition U0015;
    private static SwiftTagSubItemDefinition U0016;
    private static SwiftTagSubItemDefinition U0017;
    private static SwiftTagSubItemDefinition U0018;
    private static SwiftTagSubItemDefinition U0019;
    private static SwiftTagSubItemDefinition U001A;
    private static SwiftTagDefinition U001B;
    private static SwiftTagSubItemDefinition U001C;
    private static SwiftTagSubItemDefinition U001D;

    [Description("Sequential section number")]
    public Tag202 SectionNumber_202
    {
      get
      {
        return new Tag202((SwiftElement) this, 0, (SwiftDefinitionElement) MT051.U0002);
      }
    }

    [Description("Sequential section number")]
    public Tag202 Tag202_SectionNumber
    {
      get
      {
        return this.SectionNumber_202;
      }
    }

    [Description("Total number of sections in a multi-section message.")]
    public Tag203 TotalSections_203
    {
      get
      {
        return new Tag203((SwiftElement) this, 0, (SwiftDefinitionElement) MT051.U0004);
      }
    }

    [Description("Total number of sections in a multi-section message.")]
    public Tag203 Tag203_TotalSections
    {
      get
      {
        return this.TotalSections_203;
      }
    }

    [Description("9th character of BIC-12.")]
    public MT051.SequenceClass[] Sequence
    {
      get
      {
        int index = -1;
        List<MT051.SequenceClass> list = new List<MT051.SequenceClass>();
        int count;
        do
        {
          ++index;
          MT051.SequenceClass sequenceClass = new MT051.SequenceClass((SwiftElement) this, index, false);
          count = this.ListTags((SwiftElement) sequenceClass).Count;
          if (count > 0)
            list.Add(sequenceClass);
        }
        while (count > 0);
        return list.ToArray();
      }
    }

    public MT051()
      : base(true)
    {
    }

    public MT051(SwiftMessage message)
      : base(message)
    {
    }

    public MT051.SequenceClass AddSequence()
    {
      return new MT051.SequenceClass((SwiftElement) this, this.Sequence.Length, true);
    }

    public void RemoveSequence(MT051.SequenceClass sequence)
    {
      foreach (SwiftTag tag in this.ListTags((SwiftElement) sequence))
        this.RemoveTag(tag);
    }

    internal override SwiftMessageDefinition MsgDefinition()
    {
      return MT051.MessageDefinition;
    }

    protected override void InitSwiftMessageDefinition()
    {
      MT051.MessageDefinition = new SwiftMessageDefinition("MT051", "Session History Report");
      MT051.U0002 = new SwiftTagDefinition("SectionNumber_202", "Sequential section number");
      MT051.U0002.TagName = "{202:";
      MT051.U0003 = new SwiftTagSubItemDefinition("SectionNumber", "Sequential section number");
      MT051.U0002.Elements.Add((SwiftDefinitionElement) MT051.U0003);
      MT051.MessageDefinition.Elements.Add((SwiftDefinitionElement) MT051.U0002);
      MT051.U0004 = new SwiftTagDefinition("TotalSections_203", "Total number of sections in a multi-section message.");
      MT051.U0004.TagName = "{203:";
      MT051.U0005 = new SwiftTagSubItemDefinition("TotalSections", "Total number of sections in a multi-section message.");
      MT051.U0004.Elements.Add((SwiftDefinitionElement) MT051.U0005);
      MT051.MessageDefinition.Elements.Add((SwiftDefinitionElement) MT051.U0004);
      MT051.U0006 = new SwiftTagSequenceDefinition("Sequence", "9th character of BIC-12.");
      MT051.U0006.Multiple = true;
      MT051.U0007 = new SwiftTagDefinition("LTCode_305", "9th character of BIC-12.");
      MT051.U0007.TagName = "{305:";
      MT051.U0008 = new SwiftTagSubItemDefinition("LTCode", "9th character of BIC-12.");
      MT051.U0007.Elements.Add((SwiftDefinitionElement) MT051.U0008);
      MT051.U0006.Elements.Add((SwiftDefinitionElement) MT051.U0007);
      MT051.U000E = new SwiftTagDefinition("SessionInformation_331", "SessionIinformation,");
      MT051.U000E.TagName = "{331:";
      MT051.U000E.Mandatory = false;
      MT051.U000E.Multiple = true;
      MT051.U000F = new SwiftTagSubItemDefinition("SessionNumber", "Session information,");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U000F);
      MT051.U0010 = new SwiftTagSubItemDefinition("DateSessionOpened", "date session opened");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0010);
      MT051.U0011 = new SwiftTagSubItemDefinition("TimeSessionOpened", " time session opened");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0011);
      MT051.U0012 = new SwiftTagSubItemDefinition("DateSessionClosed", "date session closed");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0012);
      MT051.U0013 = new SwiftTagSubItemDefinition("TimeSessionClosed", "time session closed");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0013);
      MT051.U0014 = new SwiftTagSubItemDefinition("ErrorCode", "reason for closure");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0014);
      MT051.U0015 = new SwiftTagSubItemDefinition("ISNQuantity", "quantity of messages sent");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0015);
      MT051.U0016 = new SwiftTagSubItemDefinition("OSNQuantity", "quantity of messages received");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0016);
      MT051.U0017 = new SwiftTagSubItemDefinition("FirstISN", " first ISN");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0017);
      MT051.U0018 = new SwiftTagSubItemDefinition("LastISN", "lastISN");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0018);
      MT051.U0019 = new SwiftTagSubItemDefinition("FirstOSN", " first OSN");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U0019);
      MT051.U001A = new SwiftTagSubItemDefinition("LastOSN", "lastOSN");
      MT051.U000E.Elements.Add((SwiftDefinitionElement) MT051.U001A);
      MT051.U0006.Elements.Add((SwiftDefinitionElement) MT051.U000E);
      MT051.U001B = new SwiftTagDefinition("LTSummary_332", "LT summary,");
      MT051.U001B.TagName = "{332:";
      MT051.U001C = new SwiftTagSubItemDefinition("ISNQuantity", "Total Messages Sent");
      MT051.U001B.Elements.Add((SwiftDefinitionElement) MT051.U001C);
      MT051.U001D = new SwiftTagSubItemDefinition("OSNQuantity", "Total Messages Received");
      MT051.U001B.Elements.Add((SwiftDefinitionElement) MT051.U001D);
      MT051.U0006.Elements.Add((SwiftDefinitionElement) MT051.U001B);
      MT051.MessageDefinition.Elements.Add((SwiftDefinitionElement) MT051.U0006);
    }

    public class SequenceClass : SwiftTagSequence
    {
      internal override SwiftDefinitionElement Definition
      {
        get
        {
          return (SwiftDefinitionElement) MT051.U0006;
        }
      }

      [Description("9th character of BIC-12.")]
      public Tag305 LTCode_305
      {
        get
        {
          return new Tag305((SwiftElement) this, 0, (SwiftDefinitionElement) MT051.U0007);
        }
      }

      [Description("9th character of BIC-12.")]
      public Tag305 Tag305_LTCode
      {
        get
        {
          return this.LTCode_305;
        }
      }

      [Description("SessionIinformation,")]
      public Tag331[] SessionInformation_331
      {
        get
        {
          int index = -1;
          List<Tag331> list = new List<Tag331>();
          int count;
          do
          {
            ++index;
            Tag331 tag331 = new Tag331((SwiftElement) this, index, (SwiftDefinitionElement) MT051.U000E);
            count = this.ListTags((SwiftElement) tag331).Count;
            if (count > 0)
              list.Add(tag331);
          }
          while (count > 0);
          return list.ToArray();
        }
      }

      [Description("SessionIinformation,")]
      public Tag331[] Tag331_SessionInformation
      {
        get
        {
          return this.SessionInformation_331;
        }
      }

      [Description("LT summary,")]
      public Tag332 LTSummary_332
      {
        get
        {
          return new Tag332((SwiftElement) this, 0, (SwiftDefinitionElement) MT051.U001B);
        }
      }

      [Description("LT summary,")]
      public Tag332 Tag332_LTSummary
      {
        get
        {
          return this.LTSummary_332;
        }
      }

      internal SequenceClass(SwiftElement parent, int index, bool createTags)
        : base(parent, index, createTags)
      {
      }

      public Tag331 AddSessionInformation_331()
      {
        return new Tag331((SwiftElement) this, this.SessionInformation_331.Length, (SwiftDefinitionElement) MT051.U000E)
        {
          Value = string.Empty
        };
      }

      public void RemoveSessionInformation_331(Tag331 tag)
      {
        this.RemoveTag(tag.GetTag());
      }
    }
  }
}
